package com.cordova.test.imageselect.module

import android.os.Parcel
import android.os.Parcelable

class ImageItem : Parcelable {
    var name: String? = null
    /**图片的名字*/
    var path: String? = null
    /**图片的路径*/
    var size: Long = 0
    /**图片的大小*/
    var width: Int = 0
    /**图片的宽度*/

    var height: Int = 0
    /**图片的高度*/
    var mimeType: String? = null
    /**图片的类型*/
    var addTime: Long = 0

    /**图片的创建时间*/

    constructor(parcel: Parcel) {
        this.name = parcel.readString()
        this.path = parcel.readString()
        this.size = parcel.readLong()
        this.width = parcel.readInt()
        this.height = parcel.readInt()
        this.mimeType = parcel.readString()
        this.addTime = parcel.readLong()
    }

    constructor()

    /** 图片的路径和创建时间相同就认为是同一张图片  */
    override fun equals(o: Any?): Boolean {
        if (o is ImageItem) {
            val item = o as ImageItem?
            return this.path.equals(item!!.path, ignoreCase = true) && this.addTime == item.addTime
        }

        return super.equals(o)
    }

    override fun writeToParcel(p0: Parcel?, p1: Int) {
        p0?.writeString(this.name)
        p0?.writeString(this.path)
        p0?.writeLong(this.size)
        p0?.writeInt(this.width)
        p0?.writeInt(this.height)
        p0?.writeString(this.mimeType)
        p0?.writeLong(this.addTime)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<ImageItem> {
        override fun createFromParcel(parcel: Parcel): ImageItem {
            return ImageItem(parcel)
        }

        override fun newArray(size: Int): Array<ImageItem?> {
            return arrayOfNulls(size)
        }
    }

}